package com.thon.service.project.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thon.dao.project.ProjectAdDao;
import com.thon.entity.project.Project;
import com.thon.entity.project.ProjectAd;
import com.thon.service.project.ProjectAdService;

@Service
@Transactional
public class ProjectAdServiceImpl implements ProjectAdService {

	@Autowired
	private ProjectAdDao projectAdDao;

	@Override
	public void add(ProjectAd projectAd) {
		projectAdDao.save(projectAd);
	}

	@Override
	public ProjectAd getProjectAdByNow(Integer projectId) {	
		Object object=projectAdDao.getProjectAdByNow(projectId);
		ProjectAd pa=new ProjectAd();
		Object[] o=(Object[])object;
		if(o!=null){
			Integer paId=Integer.valueOf(o[0].toString());
			String content=o[1].toString();
			Date createdDate=(Date)o[2];
			Integer pid=Integer.valueOf(o[3].toString());
			String title=o[4].toString();
			Project p=new Project();
			p.setId(pid);
			
			pa.setId(paId);
			pa.setContent(content);
			pa.setCreatedDate(createdDate);
			pa.setProject(p);
			pa.setTitle(title);
		}
		return pa;
	}
}
